flask |
您所在的位置:网站首页 › flask cache › flask |
Flask-cache-manifest is a Flask extension to help you serve your md5 hashed assets. Having file hashes in filenames is a popular feature of modern asset bundlers. It's a good strategy for browser cache busting. However, Flask does not provide an easy way to reference those complicated and ever-changing filenames. Flask-cache-manifest lets you reference those assets by leveraging cache_manifest.json files. Full Documentation: https://maxdup.github.io/flask-cache-manifest/ Turns: into: Installation pip install flask-cache-manifest InitializingThe extension needs to be loaded alongside your Flask application. Here's how it's done: from flask import Flask, Blueprint from flask_cache_manifest import FlaskCacheManifest flaskCacheManifest = FlaskCacheManifest() app = Flask('my-app', static_folder='dist/static', static_url_path='/static') bp = Blueprint('my-blueprint', __name__, static_folder='blueprints/static', static_url_path='/bp/static') app.register_blueprint(bp) flaskCacheManifest.init_app(app) app.run()NOTE: Ideally, flaskCacheManifest.init_app needs to be called after you've registered your blueprints. Static folders registered after init_app will not be loaded. UsageFlask-cache-manifest adds the hashed_url_for function for use in your templates. It is analogous to Flask's url_for. Given the above example and its blueprints, here's how you would be able to reference your static files in your Jinja templates. |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |